﻿using System;
using System.Collections.Generic;
using Common;
using DataAccess;
using Entity;
using System.Data;

namespace Business
{
    /// <summary>
    /// Summary description for ArticleBusiness
    /// </summary>
    public class ArticleBusiness : AbstractBusiness
    {
        private readonly ArticleDAL _articleDal;
        public ArticleBusiness()
        {
            _articleDal = new ArticleDAL();
        }

        public void Update(Guid id, string title, string content, string user, Guid category, string brief)
        {
            Article article = new Article();
            article.Id = id;
            article.Title = title;
            article.Content = content;
            article.User = user;
            article.Category = category;
            article.Brief = brief;
            _articleDal.Update(article);
        }

        public Article GetById(Guid id)
        {
            DataTable dataTable = _articleDal.GetById(id);
            List<Article> result = new TypedList<Article>(dataTable);
            return result[0];
        }

        public List<Article> GetTopNew(int top)
        {
            DataTable dataTable = _articleDal.GetTopNew(top);
            List<Article> result = new TypedList<Article>(dataTable);
            return result;
        }

        public PaginatedInfo<Article> GetAll(string keyWord, int pageIndex, int pageSize)
        {
            return _articleDal.GetAll(keyWord, pageIndex, pageSize);
        }

        public bool Block(Guid id)
        {
            return _articleDal.Block(id);
        }
    }
}